//
//  ActivityTableViewCell.m
//  豆瓣
//
//  Created by Roach on 16/6/24.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ActivityTableViewCell.h"
#import "ActivityModel.h"
#import "UIImageView+WebCache.h"

#define kWidth self.contentView.frame.size.width
#define kHight self.contentView.frame.size.height
@interface ActivityTableViewCell ()

@property (nonatomic, retain) UIImageView *backGroundImageView;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIImageView *beginImageView;
@property (nonatomic, retain) UILabel *beginTimeLabel;
@property (nonatomic, retain) UILabel *endTimeLabel;
@property (nonatomic, retain) UIImageView *addressImageView;
@property (nonatomic, retain) UILabel *addressLabel;
@property (nonatomic, retain) UIImageView *categoryImageView;
@property (nonatomic, retain) UILabel *categoryLabel;
@property (nonatomic, retain) UILabel *categorytextLabel;
@property (nonatomic, retain) UILabel *wisherLabel;
@property (nonatomic, retain) UILabel *wisherNumberLabel;
@property (nonatomic, retain) UILabel *participantLabel;
@property (nonatomic, retain) UILabel *participantNumberLabel;
@property (nonatomic, retain) UIImageView *pictureImageView;
@property (nonatomic, retain) UIImageView *writeBackGround;

@end


@implementation ActivityTableViewCell

- (void)dealloc {
    
    [_backGroundImageView release];
    [_titleLabel release];
    [_beginImageView release];
    [_beginTimeLabel release];
    [_endTimeLabel release];
    [_addressImageView release];
    [_addressLabel release];
    [_categoryImageView release];
    [_categoryLabel release];
    [_wisherLabel release];
    [_wisherNumberLabel release];
    [_participantLabel release];
    [_participantNumberLabel release];
    [_pictureImageView release];
    [_cellModel release];
    [_writeBackGround release];
    [super dealloc];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self  = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        // 背景
        self.backGroundImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_backGroundImageView];
        [_backGroundImageView release];
        
        // 白色底色
        self.writeBackGround = [[UIImageView alloc]init];
        [self.contentView addSubview:_writeBackGround];
        [_writeBackGround release];
        
        // 标题
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_titleLabel];
        [_titleLabel release];
        
        // 开始图标
        self.beginImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_beginImageView];
        [_beginImageView release];
        
        // 开始时间
        self.beginTimeLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_beginTimeLabel];
        [_beginTimeLabel release];
        
        // 结束时间
        self.endTimeLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_endTimeLabel];
        [_endTimeLabel release];
        
        // 地点图标
        self.addressImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_addressImageView];
        [_addressImageView release];
        
        // 地点
        self.addressLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_addressLabel];
        [_addressLabel release];
        
        // 类型图标
        self.categoryImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_categoryImageView];
        [_categoryImageView release];
        
        // 类型
        self.categoryLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_categoryLabel];
        [_categoryLabel release];
        
        // 类型······
        self.categorytextLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_categorytextLabel];
        [_categorytextLabel release];
        
        // 感兴趣
        self.wisherLabel = [[UILabel alloc]init];
        [self.contentView addSubview: _wisherLabel];
        [_wisherLabel release];
        
        //
        self.wisherNumberLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_wisherNumberLabel];
        [_wisherNumberLabel release];
        
        // 参加
        self.participantLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_participantLabel];
        [_participantLabel release];
        
        self.participantNumberLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_participantNumberLabel];
        [_participantNumberLabel release];
        
        // 图片
        self.pictureImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_pictureImageView];
        [_pictureImageView release];
        
    }
    
    return self;
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    // 背景
    self.backGroundImageView.frame = CGRectMake(10, 15, kWidth - 20, kHight - 20);
//    _backGroundImageView.backgroundColor = [UIColor blueColor];
    
    // 标题
    self.titleLabel.frame = CGRectMake(15, 20, kWidth - 30, kHight * 0.1);
//    _titleLabel.backgroundColor = [UIColor yellowColor];
    
    // 白色背景
    self.writeBackGround.frame = CGRectMake(13, 45, kWidth - 26, kHight - 58);
//    _writeBackGround.backgroundColor = [UIColor whiteColor];
    
    // 开始时间图标
    self.beginImageView.frame = CGRectMake(20, 51, 23, 23);
//    _beginImageView.backgroundColor = [UIColor greenColor];
    
    // 开始时间
    self.beginTimeLabel.frame = CGRectMake(47, 51, kWidth * 0.53, 23);
//    _beginTimeLabel.backgroundColor = [UIColor grayColor];
    
    // 地点图标
    self.addressImageView.frame = CGRectMake(20, 81, 23, 23);
//    _addressImageView.backgroundColor = [UIColor greenColor];
    
    // 地点
    self.addressLabel.frame = CGRectMake(47, 81, kWidth * 0.53, 23);
//    _addressLabel.backgroundColor = [UIColor grayColor];
    
    // 类型图标
    self.categoryImageView.frame = CGRectMake(20, 111, 23, 23);
//    _categoryImageView.backgroundColor = [UIColor greenColor];
    
    // 类型
    self.categoryLabel.frame = CGRectMake(87, 111, kWidth * 0.45, 23);
//    _categoryLabel.backgroundColor = [UIColor grayColor];
    
    // “类型”
    self.categorytextLabel.frame = CGRectMake(47, 111, 53, 23);
//    _categorytextLabel.font = [UIFont systemFontOfSize:13];
    _categorytextLabel.text = @"类型：";
    
    // 感兴趣
    self.wisherLabel.frame = CGRectMake(20, 150, 53, 23);
    _wisherLabel.font = [UIFont systemFontOfSize:13];
    _wisherLabel.text = @"感兴趣：";
    
    // 感兴趣number
    self.wisherNumberLabel.frame = CGRectMake(70, 150, 50, 23);
//    _wisherNumberLabel.backgroundColor = [UIColor redColor];
    
    //参加
    self.participantLabel.frame = CGRectMake(150, 150, 52, 23);
    _participantLabel.text = @"参加：";
    _participantLabel.font = [UIFont systemFontOfSize:13];
    
    // 参加Number
    self.participantNumberLabel.frame = CGRectMake(185, 150, 50, 23);
//    _participantNumberLabel.backgroundColor = [UIColor redColor];
    
    // 图片
    self.pictureImageView.frame = CGRectMake(270, 45, kWidth * 0.3, kHight * 0.7);
//    _pictureImageView.backgroundColor = [UIColor orangeColor];
    
}

- (void)setCellModel:(ActivityModel *)cellModel {
    
    if (_cellModel != cellModel) {
        [_cellModel release];
        _cellModel = [cellModel retain];
        
    }
    
    NSURL *url = [NSURL URLWithString:cellModel.image];
    
    [_pictureImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    
    _titleLabel.text =cellModel.title;
    [_beginImageView setImage:[UIImage imageNamed:@"icon_date"]];
    [_addressImageView setImage:[UIImage imageNamed:@"icon_spot"]];
    [_categoryImageView setImage:[UIImage imageNamed:@"icon_catalog"]];
    [_writeBackGround setImage:[UIImage imageNamed:@"bg_share_large"]];
    [_backGroundImageView setImage:[UIImage imageNamed:@"bg_eventlistcell@2x"]];
    
    _beginTimeLabel.text = cellModel.begin_time;
    _addressLabel.text = cellModel.address;
    _categoryLabel.text = cellModel.category_name;
    NSString *str = [NSString stringWithFormat:@"%@", cellModel.wisher_count];
    _wisherNumberLabel.text = str;
    NSString *str2 = [NSString stringWithFormat:@"%@", cellModel.participant_count];
    _participantNumberLabel.text = str2;
    
    
}

@end
